
function main( ui ) {

 
  //var o = new JSONObject( );
   
    
   //o.put("cloudId","1111");
   //o.put("username","acasolla");
  
  
  // var arr = new JSONArray();

  //arr.put(o);
  // return o.toString(); 
 //return arr.toString();
 /*
  var obj= {"title":"My first q","questions":[{"input":{"hint":"Your Name","inputType":"TEXT","actions":[{"actionType":"NEXT","label":"Next"}],"name":"Enter your name :","type":"INPUT"},"title":"Whats your name?"},{"answerGroup":{"answers":["1 - Giggione","2 - Bono","3 - Cocciante"],"singleChoice":true,"actions":[{"actionType":"BACK","label":"Back"},{"actionType":"NEXT","label":"Next"}],"name":"singers","type":"ANSWERGROUP"},"title":"Whats your favourite singer?"}]};
  var obj2= {"title":"My second q","questions":[{"input":{"hint":"Your Name","inputType":"TEXT","actions":[{"actionType":"NEXT","label":"Next"}],"name":"Enter your surname :","type":"INPUT"},"title":"Whats your surname?"},{"answerGroup":{"answers":["1 - Pet","2 - Pat","3 - Pit"],"singleChoice":true,"actions":[{"actionType":"BACK","label":"Back"},{"actionType":"NEXT","label":"Next"}],"name":"singers","type":"ANSWERGROUP"},"title":"Whats your favourite cip?"}]};
  */
  
  var obj = {
  "title": "First Questionnaire",
  "questions": [
    {
      "title": "What\u0027s your name?",
      "input": {
        "hint": "Your Name",
        "inputType": "TEXT",
        "name": "Enter your name :",
        "type": "INPUT",
        "actions": [
          {
            "label": "Next",
            "actionType": "NEXT"
          }
        ]
      }
    },
    {
      "title": "What\u0027s your email?",
      "input": {
        "hint": "Your Email",
        "inputType": "EMAIL",
        "name": "Enter your email :",
        "type": "INPUT",
        "actions": [
          {
            "label": "Back",
            "actionType": "BACK"
          },
          {
            "label": "Next",
            "actionType": "NEXT"
          }
        ]
      }
    },
    {
      "title": "What\u0027s your age?",
      "input": {
        "hint": "Your age",
        "inputType": "NUMERIC",
        "name": "Enter your Age",
        "type": "INPUT",
        "actions": [
          {
            "label": "Back",
            "actionType": "BACK"
          },
          {
            "label": "Next",
            "actionType": "NEXT"
          }
        ]
      }
    },
    {
      "title": "What\u0027s your favourite color?",
      "answerGroup": {
        "singleChoice": true,
        "answers": [
          "Red",
          "Blu",
          "Green",
          "Purple PurplePurplePurple PurplePurple",
          "Black black black blackblackblack",
          "White",
          "Gold",
          "Platinum"
        ],
        "name": "colors",
        "type": "ANSWERGROUP",
        "actions": [
          {
            "label": "Back",
            "actionType": "BACK"
          },
          {
            "label": "Next",
            "actionType": "NEXT"
          }
        ]
      }
    },
    {
      "title": "What\u0027s your favourite singer?",
      "answerGroup": {
        "singleChoice": true,
        "answers": [
          "1 - Giggione",
          "2 - Bono",
          "3 - Cocciante"
        ],
        "name": "singers",
        "type": "ANSWERGROUP",
        "actions": [
          {
            "label": "Back",
            "actionType": "BACK"
          },
          {
            "label": "Next",
            "actionType": "NEXT"
          }
        ]
      }
    }
  ]
};
  
  var obj2 = {
  "title": "Second Questionnaire",
  "questions": [
    {
      "title": "What\u0027s your surname?",
      "input": {
        "hint": "Your Surame",
        "inputType": "TEXT",
        "name": "Enter your surname :",
        "type": "INPUT",
        "actions": [
          {
            "label": "Next",
            "actionType": "NEXT"
          }
        ]
      }
    },
    {
      "title": "What\u0027s your profession?",
      "answerGroup": {
        "singleChoice": true,
        "answers": [
          "Student",
          "Driver",
          "Astronaut",
          "Other"
        ],
        "name": "profession",
        "type": "ANSWERGROUP",
        "actions": [
          {
            "label": "Back",
            "actionType": "BACK"
          },
          {
            "label": "Next",
            "actionType": "NEXT"
          }
        ]
      }
    },
    {
      "title": "What\u0027s your continent?",
      "answerGroup": {
        "singleChoice": true,
        "answers": [
          "Europe",
          "America",
          "Asia"
        ],
        "name": "place",
        "type": "ANSWERGROUP",
        "actions": [
          {
            "label": "Back",
            "actionType": "BACK"
          },
          {
            "label": "Next",
            "actionType": "NEXT"
          }
        ]
      }
    }
  ]
}


 
  
  var arr = new JSONArray();
  arr.put( toJSON(obj) );
  arr.put( toJSON(obj2) );
  
  return arr;
   
}



function registerUser( login, deviceId ) {

  var a = EntityManager.findAccountByLogin( login) ;
  
  var u = new UserEntity();
  
  u.deviceId = deviceId;
 
  a.setUser( u );
  
  var uuid = EntityManager.registerUser( u, a );
  

  return uuid;
}


function register_test( ui ) {
 
  var json = ui.getQueryParameters().getFirst("auth");
  var r = "noValues";
  if ( json == null ){
      return r;
  }
  var o = new JSONObject( json );
  
  var deviceId = o.getString("deviceId");
  o.put("cloudId","device-"+deviceId);
  
  
  return o.toString();
}